package io.yunho.yunho.interview.two.threadlocal.ref;

import java.lang.ref.WeakReference;

/**
 * @author: Jason
 * @date: 2021/4/27 17:30
 * @description:
 */
public class WeakReferDemo {
    static class WeakReferTest{
        protected void finalize() throws Throwable{
            System.out.println("弱引用的对象被回收了");
        }
    }

    public static void main(String[] args) {
        WeakReference<WeakReferTest> wr = new WeakReference<>(new WeakReferTest());
        System.out.println("gc 前，弱引用的真实对象："+wr.get());
        System.gc();
        System.out.println("gc 后，弱引用的真实对象："+wr.get());
        System.out.println("gc 后，弱引用的对象本身："+wr);

    }
}
